var express = require('express');
var router = express.Router();
var multer = require('multer');
var path = require('path');
const userctrls= require('../ctrls/users')



// 配置 multer 存储路径和文件名
var storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, path.join(__dirname, '../public/images/avatar'));
  },
  filename: function (req, file, cb) {
    // 用时间戳+原始名防止重名
    const ext = path.extname(file.originalname);
    cb(null, Date.now() + ext);
  }
});

var upload = multer({ storage: storage });
// 用户登录
router.post('/login', userctrls.login );

// 用户注册
router.post('/reg', upload.single('avatar'), userctrls.regist);

// 用户注册完成后传用户信息
router.post('/userId', userctrls.getUserId);
router.post('/userRecord', userctrls.getUserRecord);

// 获取用户信息
router.get('/userTable',(res,req,next)=>{
  console.log('获取用户信息')
  userctrls.getAllUsers(res,req,next)
})
// 获取所有对战信息
router.get('/recordTable',userctrls.getAllRecord)
// 保存对战信息
router.post('/addRecord',userctrls.addRecord)
router.post('/logout',userctrls.logout)
module.exports = router;
